
#include "test_audio-player.hpp"
#include "zen_file.h"

using namespace std;

int main()
{
	auto loader = std::make_shared<Zen::WavAudioLoader>();
	auto coder = std::make_shared<Zen::AudioWav>();
	auto player = Zen::AudioPlayer::CreatePlayer();

	auto cache = player->GetCache();
	cache->SetDelegate(loader);

	std::string path = "bing0.wav";

	auto src = cache->GetShared(path);
	if (!src) return -2;
	//auto audio = cache->loadAudio(Zen::CreateSineWave(1, 1, 44100, 2000, 1));
	//cache->cacheAudio(src, audio);

	Zen::AudioTrackID loopId = 0;
	std::string a;
	do
	{
		if (a == "stop")
		{
			player->StopAllTracks();
		}
		else if (a == "play")
		{
			loopId = player->Play(src, 0);
		}
		else if (a == "loop")
		{
			loopId = player->Play(src, 1);
		}
		else if (a == "pause")
		{
			player->PausePlayer();
		}
		else if (a == "resume")
		{
			player->ResumePlayer();
		}
		else if (a == "ploop")
		{
			player->Pause(loopId);
		}
		else if (a == "rloop")
		{
			player->Resume(loopId);
		}
		else if (a == "sloop")
		{
			player->Stop(loopId);
		}
		else if (a == "load")
		{
			std::string file;
			cin >> file;
			auto t = cache->GetShared(file);
			if (!t)
			{
				cout << "error to load file:" << file << endl;
			}
			else
			{
				cout << "load ok";
				src = t;
			}
		}
		else
		{
			cout << "command list: \n play/stop/loop/pause/resume/ploop/rloop/sloop/load <file-path>/" << endl;
		}
		if (player->IsPlayerPaused())
		{
			cout << "--- paused ---" << endl;
		}
		cin.clear();
	} while (cin >> a);
	return 0;
}
